package com.xc.controller;

import com.xc.mapper.DeptMapper;
import com.xc.pojo.Dept;
import com.xc.pojo.Result;
import com.xc.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 部门管理Controller
 */
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    DeptService deptService;

    @GetMapping
    public Result selectAll() {
        return Result.success(deptService.selectAll());
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        int effortRows = deptService.deleteById(id);
        if (effortRows == 1)
            return Result.success();
        else
            return Result.success("删除失败咯，客官再来呀");
    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        return Result.success(deptService.selectById(id));
    }

    @PostMapping()
    public Result insertDept(@RequestBody Dept dept) {
        int effortRows = deptService.insertDept(dept);
        if (effortRows == 1)
            return Result.success();
        else
            return Result.success("添加失败咯，客官再来呀");
    }

    @PutMapping
    public Result updateDept(@RequestBody Dept dept) {
        int effortRows = deptService.updateDept(dept);
        if (effortRows == 1)
            return Result.success();
        else
            return Result.success("修改失败咯，客官再来呀");

    }
}
